package com.cike.sparkstudy.core.java;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

/**
 * RDD持久化操作
 */
public class Persist {

    public static void main(String[] args) {

        SparkConf conf = new SparkConf().setAppName("Persist").setMaster("local");
        JavaSparkContext sc = new JavaSparkContext(conf);

        JavaRDD<String> lines = sc.textFile("D://DevelopeCodes//DemoData//sparktest1.txt");

        long beginTime = System.currentTimeMillis();
        long count = lines.count();

        long endTime = System.currentTimeMillis();

        System.out.println(count+"首次统计文件总行数花费了："+(endTime-beginTime)+"   milliseconds");

        beginTime = System.currentTimeMillis();
        count = lines.count();
        endTime = System.currentTimeMillis();
        System.out.println(count+"第二次统计文件总行数花费了 ："+(endTime-beginTime)+"   milliseconds");


        sc.close();
    }

}
